package com.niit.controller;

import com.niit.pojo.Dept;
import com.niit.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: springcloud
 * @description:
 * @author: XZQ
 * @create: 2019-12-02 11:14
 **/
@RestController
public class controller {

    @Autowired
    private DeptService deptService;

    @PostMapping("/dept/add")
    public boolean addDept(@RequestBody Dept dept) {
//        System.out.println(dept.getDname());
        return deptService.addDept(dept);
    }

    @GetMapping("/dept/get/{id}")
    public Dept get(@PathVariable("id") Long id) {
        return deptService.queryById(id);
    }

    @GetMapping("/dept/list")
    public List<Dept> list() {
        List<Dept> depts = deptService.queryAll();
        System.out.println(depts);
        return depts;
    }

    @DeleteMapping("/dept/delete/{id}")
    public void delete(@PathVariable Long id) {
        deptService.deleteById(id);
    }
}
